<script setup lang="ts">
import FinanciaYoyTab from '@/components/Echart/Table/FinanciaYoyTab.vue'
import FinanciaDiong from '@/components/Echart/Table/FinanciaDiong.vue'
import AnimationDialog from '@/components/Dialog/AnimationDialog.vue'
import { reactive, watch, ref, nextTick } from 'vue'
import { storeToRefs } from 'pinia'
import { useFinanceStore } from '@/stores/module/finance'
const FinanceStore = useFinanceStore() // 创建store实例
const { getIncomeYOY } = storeToRefs(FinanceStore)
const barValues = getIncomeYOY.value?.info[0]?.bar?.value
const lineValues = getIncomeYOY.value?.info[0]?.line?.value
const subTitles = getIncomeYOY.value?.sub_titles
const tableHeadData = reactive(getIncomeYOY.value?.info[0]?.tableHeadData)
const tableBodyData = reactive(
  subTitles?.map((title, index) => ({
    id: index.toString(),
    name: title,
    valueDifference: barValues[index],
    YoYIncrease: lineValues[index],
  }))
)

const title = ref(getIncomeYOY.value.title)
const dialogInfo = {
  title: title.value, // 标题
  style: 'lb', // 弹窗位置，例如右中
  width: '50%', // 宽度
}
const dialog = ref(null)
const btn = async () => {
  await nextTick()
  dialog.value.changeDialogVisible(true)
}
</script>
<template>

    <card-box>
      <template v-slot:title>
        <h1>{{ getIncomeYOY.title }}</h1>
      </template>
      <button
        @click="btn"
        class="see-more-btn"
        size="small"
        v-if="tableBodyData.length > 5"
      >
        {{ $t('bi_front_distributorseemore') }}
      </button>
      <FinanciaYoyTab
        :table-head-data="tableHeadData"
        :table-body-data="tableBodyData"
        v-if="tableBodyData.length && tableHeadData.length"
      />
      <div v-else class="default-img">
        <p>{{ $t('bi_common_nodata') }}</p>
      </div>
    </card-box>
  
  <AnimationDialog
    ref="dialog"
    :dialogInfo="dialogInfo"
    class="transactionData"
    style="background-color: rgba(11, 31, 86, 0.5)"
  >
    <FinanciaDiong
      :table-head-data="tableHeadData"
      :table-body-data="tableBodyData"
    />
  </AnimationDialog>
</template>
<style lang="scss" scoped>
.default-img {
  width: 100%;
  text-align: center;
  padding: 120px 0;
  background-image: url('@/assets/images/canvsimage/default.png');
  background-repeat: no-repeat;
  background-position: center;
  font-size: 16px;
  color: #00f6ff;
}

.see-more-btn {
  position: relative;
  z-index: 100;
  width: 100px;
  height: 25px;
  text-align: center;
  float: right;
  margin-top: -30px;
  font-size: 10px;
  background-color: rgba(0, 53, 171, 0.8);
  border: 1px solid #0b45ca;
  color: #00f6ff;
  cursor: pointer;
}
.dialog-fade-enter-active .el-dialog.transactionData {
  animation: tilt-in-left 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes tilt-in-left {
  0% {
    -webkit-transform: rotateX(-30deg) translateX(-300px) skewX(-30deg);
    transform: rotateX(-30deg) translateX(-300px) skewX(-30deg);
    opacity: 0;
  }
  100% {
    -webkit-transform: rotateX(0deg) translateX(0) skewX(0deg);
    transform: rotateX(0deg) translateX(0) skewX(0deg);
    opacity: 1;
  }
}
</style>
